﻿
@{
    ViewData["Title"] = "GridView";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
@model List<EasyToHelp.Entity.GridManageField>
<blockquote class="layui-elem-quote layui-text">
    <div class="layui-form layui-card-header layuiadmin-card-header-auto">
        <div class="layui-form-item">
            @Html.Raw(ViewBag.WhereList)
            <div class="layui-inline">
                <button class="layui-btn layuiadmin-btn-list" lay-submit="" lay-filter="LAY-app-contlist-search">
                    <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                    搜索
                </button>
            </div>
        </div>
    </div>
</blockquote>
<table class="layui-hide" id="test" lay-filter="test"></table>
<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-normal layui-btn-sm" lay-event="Add">新增</button>
        <button class="layui-btn layui-btn-warm layui-btn-sm" lay-event="Edit">编辑</button>
        <button class="layui-btn layui-btn-danger layui-btn-sm" lay-event="Del">删除</button>
       
    </div>
</script>
<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
    <button class="layui-btn layui-btn-danger layui-btn-xs" lay-event="fieldms">字段管理</button>
</script>
<script>
    layui.use('table', function () {
        var table = layui.table;
        table.render({
            elem: '#test'
            , url: '/GridManage/GridData?Table=@ViewBag.Table&WhereJson=1'
            , toolbar: '#toolbarDemo'
            , title: '用户数据表'
            , cellMinWidth: 80 //全局定义常规单元格的最小宽度，layui 2.2.1 新增
            , cols: [[
                @Html.Raw(ViewBag.FieldList)
            ]]
            , page: true
        });
        //头工具栏事件
        table.on('toolbar(test)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            switch (obj.event) {
                case 'getCheckData':
                    var data = checkStatus.data;
                    if (data.length > 0) {
                        layer.alert(JSON.stringify(data));
                    }
                    else
                    {
                        layer.msg('请至少选择一个');
                    }
                    break;
                case 'Add':
                    Add();
                    break;
                case 'Edit':
                    var data = checkStatus.data;
                    if (data.length == 1) {
                        alert(data.Id);
                        layer.alert(JSON.stringify(data));
                    }
                    else {
                        layer.msg('编辑只能选择一个');
                    }
                    break;
                case 'Del':
                    var data = checkStatus.data;
                    if (data.length > 0) {
                        layer.alert(JSON.stringify(data));
                    }
                    else {
                        layer.msg('请至少选择一个');
                    }
                    break;
            };
        });
        //监听行工具事件
        table.on('tool(test)', function (obj) {
            var data = obj.data;
            //console.log(obj)
            if (obj.event === 'del') {
                layer.confirm('真的删除行么', function (index) {
                    obj.del();
                    layer.close(index);
                });
            } else if (obj.event === 'edit') {
                layer.prompt({
                    formType: 2
                    , value: data.MainTableName
                }, function (value, index) {
                    obj.update({
                        email: MainTableName
                    });
                    layer.close(index);
                });
            }
            else if (obj.event === 'fieldms') {
                
                layui.use('layer', function () {
                    var layer = layui.layer;
                    layer.open({
                        type: 2,
                        title: "列表字段维护",
                        shadeClose: true,
                        shade: 0.8,
                        area: ['100%', '600px'],
                        content: '/GridManage/GridConf?Table=' + data.MainTableName+''
                    });
                });
            }
        });
    });
    function Add() {
        layui.use('layer', function () {
            var layer = layui.layer;
            layer.open({
                type: 2,
                title: false,
                shadeClose: true,
                shade: 0.8,
                area: ['800px', '600px'],
                content: '/FormManage/FormView?TableName=ListInfo'
            });
        });
    }
</script>